package edu.vt.sdm.tcga.View;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.part.ViewPart;

import edu.vt.sdm.tcga.data.ExpressionLevel2Model;

public class RawDataView extends ViewPart {
	private TableViewer viewer = null;

	public RawDataView() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

		TableViewerColumn col = null;
		col = createColumn("Gene ID", 100, 0);
		col.setLabelProvider(new ColumnLabelProvider() {
			@Override
			public String getText(Object element) {
				ExpressionLevel2Model.Row tempRow = (ExpressionLevel2Model.Row) element;
				return  ExpressionLevel2Model.getInstance().getTableCell(tempRow.getIndex());
			}			
		});

		for(int i = 1; i <= ExpressionLevel2Model.getInstance().getSampleOfInterestList().size(); i++) {
			col = createColumn(ExpressionLevel2Model.getInstance().getSampleOfInterestList().get(i-1), 100, i);
			col.setLabelProvider(new ColumnLabelProvider() {
				@Override
				public String getText(Object element) {
					ExpressionLevel2Model.Row tempRow = (ExpressionLevel2Model.Row) element;
					return  ExpressionLevel2Model.getInstance().getTableCell(tempRow.getIndex());
				}			
			});
		}
		
		final Table table = viewer.getTable();
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		viewer.setContentProvider(new ArrayContentProvider());
		viewer.setInput(ExpressionLevel2Model.getInstance().getGeneDataOfDisplay());
	}
	
	private TableViewerColumn createColumn(String inStrTitle, int inIBound, final int inColNumber) {
		final TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
		final TableColumn tc = tvc.getColumn();
		tc.setText(inStrTitle);
		tc.setWidth(inIBound);
		tc.setResizable(true);
		tc.setMoveable(true);
		return tvc;
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
